package com.sysd.mail.smtp.command;

import com.sysd.mail.smtp.SmtpSession;
import com.sysd.mail.util.EmailUtils;

import java.io.IOException;

/**
 * project: mail
 *
 * @author bsh
 * @description RcptCommand
 * @dataTime 2023/3/28 15:11
 * @company 丽水信阳软件科技有限公司
 */
public class RcptCommand extends BaseSmtpCommand {
    public RcptCommand( ) {
        super("RCPT");
    }

    /**
     * 执行命令
     *
     * @param command     命令名称
     * @param smtpSession smtp session
     * @return smtp session
     * @throws IOException io exception
     */
    @Override
    public SmtpSession execute(String command, SmtpSession smtpSession) throws IOException {
        String arg=this.getCommandName(command);
        String emailAddress= EmailUtils.extractEmailAddress(arg.trim(),3);
        smtpSession.getEmail().getTo().add(emailAddress);
        smtpSession.write("250 Requested mail action okay, completed!\r\n");
        return smtpSession;
    }
}
